<?php

namespace App\Models\Trip\OrderPay;

use Eloquent;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;

/**
 * App\Models\Trip\OrderPay\OrderPayDetails
 *
 * @property int                $id
 * @property string             $user_id       用户
 * @property string             $trip_id       行程id
 * @property int                $trip_type     行程类型。回调更新订单判断
 * @property string             $pay_sn        支付单号
 * @property string             $order_sn      订单编号
 * @property string             $order_amount  订单金额
 * @property int                $sharing_flag  分账标识,根据订单服务商分配的账户分账此阶段或许没有
 * @property int                $separate      独立支付 1 非独立支付 0 ，火车中转含飞机票 机票可独立支付
 * @property Carbon|null        $created_at
 * @property Carbon|null        $updated_at
 * @property string             $business_type 业务类型 10 下单, 11 改签 ,20  抢票 ,21 编辑抢票任务
 * @property-read OrderPay|null $order_pay
 * @method static Builder|OrderPayDetail newModelQuery()
 * @method static Builder|OrderPayDetail newQuery()
 * @method static Builder|OrderPayDetail query()
 * @method static Builder|OrderPayDetail whereBusinessType($value)
 * @method static Builder|OrderPayDetail whereCreatedAt($value)
 * @method static Builder|OrderPayDetail whereId($value)
 * @method static Builder|OrderPayDetail whereOrderAmount($value)
 * @method static Builder|OrderPayDetail whereOrderSn($value)
 * @method static Builder|OrderPayDetail wherePaySn($value)
 * @method static Builder|OrderPayDetail whereSeparate($value)
 * @method static Builder|OrderPayDetail whereSharingFlag($value)
 * @method static Builder|OrderPayDetail whereTripId($value)
 * @method static Builder|OrderPayDetail whereTripType($value)
 * @method static Builder|OrderPayDetail whereUpdatedAt($value)
 * @method static Builder|OrderPayDetail whereUserId($value)
 * @mixin Eloquent
 */
class OrderPayDetail extends Model
{
    use HasFactory;

    protected $table = "order_pay_details";
    protected $fillable
                     = [
            'user_id',
            'trip_id',
            'trip_type',
            'pay_sn',
            'order_sn',
            'order_amount',
            'sharing_flag',
            'business_type',
        ];

    public function order_pay()
    {
        return $this->belongsTo(OrderPay::class, "pay_sn", "pay_sn");
    }

    /**
     * 支付明细金额 退款是调用此金额
     *
     * @return float
     */
    public function getRealAmount(): float
    {
        return $this->getAttribute('order_amount');
    }

    /**
     * 行程类型 主要用于反向查询不同的 订单业务
     *
     * @return int
     */
    public function getTripType(): int
    {
        return $this->getAttribute('trip_type');
    }

    /**
     * 获取系统支付单号
     *
     * @return string
     */
    public function getPaySn(): string
    {
        return $this->getAttribute('pay_sn');
    }

    /**
     * 获取订单单号
     *
     * @return string
     */
    public function getOrderSn(): string
    {
        return $this->getAttribute('order_sn');
    }

}
